﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MetaInfo;
using Base;

public partial class Admin_Meta_MetaInfoEdit : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind();
    }

    private void Bind()
    {
        string type = "";
        IMetaInfo RMeta = new RMetaInfo();
        TMetaInfo TMeta = new TMetaInfo();
        if (Request.QueryString["type"] != "" && Request.QueryString["type"] != null)
        {
            type = Request.QueryString["type"].ToString();
            //首页
            if (type.Equals("index"))
            {
                this.Label5.CssClass = "pl";
                pnltrade.Visible = false;
                pnlDetail.Visible = false;
                TMeta = RMeta.GetItem("index");
                txtIndexTitle.Value = TMeta.Title;
                txtIndexDescription.Value = TMeta.Descriptions;
                txtIndexKeywords.Value = TMeta.Keywords;
            }
            else if (type.Equals("supply"))
                this.Label1.CssClass = "pl";
            else if (type.Equals("purchase"))
                this.Label2.CssClass = "pl";
            else if (type.Equals("company"))
                this.Label3.CssClass = "pl";
            else if (type.Equals("news"))
                this.Label4.CssClass = "pl";
            else if (type.Equals("expo"))
                this.Label6.CssClass = "pl";
            else if (type.Equals("agent"))
                this.Label7.CssClass = "pl";
            else if (type.Equals("product"))
                this.Label8.CssClass = "pl";
            else if (type.Equals("know"))
                this.Label9.CssClass = "pl";
            if (!type.Equals("index"))
            {
                //各栏目首页
                TMeta = RMeta.GetItem(type + "_index");
                txtIndexTitle.Value = TMeta.Title;
                txtIndexDescription.Value = TMeta.Descriptions;
                txtIndexKeywords.Value = TMeta.Keywords;
                //分类页
                TMeta = RMeta.GetItem(type + "_trade");
                txtTradeTitle.Value = TMeta.Title;
                txtTradeDescription.Value = TMeta.Descriptions;
                txtTradeKeywords.Value = TMeta.Keywords;
                //详细页
                TMeta = RMeta.GetItem(type + "_detail");
                txtDetailTitle.Value = TMeta.Title;
                txtDetailDescription.Value = TMeta.Descriptions;
                txtDetailKeywords.Value = TMeta.Keywords;
            }
        }
        else
        {
            this.Label5.CssClass = "pl";
            pnltrade.Visible = false;
            pnlDetail.Visible = false;
            TMeta = RMeta.GetItem("index");
            txtIndexTitle.Value = TMeta.Title;
            txtIndexDescription.Value = TMeta.Descriptions;
            txtIndexKeywords.Value = TMeta.Keywords;
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string Restr = "";
        string type = "index";
        IMetaInfo RMeta = new RMetaInfo();
        TMetaInfo TMeta = new TMetaInfo();

        if (Request.QueryString["type"] != "" && Request.QueryString["type"] != null)
        {
            if (Request.QueryString["type"].ToString() != "index")
                type = Request.QueryString["type"].ToString() + "_index";
        }
        //首页
        TMeta.Type = type;
        if (txtIndexTitle.Value.Trim().Equals(string.Empty))
            Restr += "首页标题、";
        else
            TMeta.Title = txtIndexTitle.Value.Trim();
        if (txtIndexDescription.Value.Trim().Equals(string.Empty))
            Restr += "首页描述、";
        else
            TMeta.Descriptions = txtIndexDescription.Value.Trim();
        if (txtIndexKeywords.Value.Trim().Equals(string.Empty))
            Restr += "首页关键字、";
        else
            TMeta.Keywords = txtIndexKeywords.Value.Trim();
        if (Restr != "")
        {
            Restr = Restr.TrimEnd('、');
            lblMessage.Visible = true;
            lblMessage.Text = Restr + "填写有误！";
            return;
        }
        else
        {
            RMeta.Update(TMeta);
            if (type == "index")
            {
                ShowMessage("保存成功！");
                return;
            }
        }

        //列表页
        if (Request.QueryString["type"] != "" && Request.QueryString["type"] != null)
        {
            if (Request.QueryString["type"].ToString() != "index")
                type = Request.QueryString["type"].ToString() + "_trade";

            TMeta.Type = type;
            if (txtTradeTitle.Value.Trim().Equals(string.Empty))
                Restr += "列表页标题、";
            else
                TMeta.Title = txtTradeTitle.Value.Trim();
            if (txtTradeDescription.Value.Trim().Equals(string.Empty))
                Restr += "列表页描述、";
            else
                TMeta.Descriptions = txtTradeDescription.Value.Trim();
            if (txtTradeKeywords.Value.Trim().Equals(string.Empty))
                Restr += "列表页关键字、";
            else
                TMeta.Keywords = txtTradeKeywords.Value.Trim();
            if (Restr != "")
            {
                Restr = Restr.TrimEnd('、');
                lblMessage.Visible = true;
                lblMessage.Text = Restr + "填写有误！";
                return;
            }
            else
            {
                RMeta.Update(TMeta);
            }
        }

        //详细页
        if (Request.QueryString["type"] != "" && Request.QueryString["type"] != null)
        {
            if (Request.QueryString["type"].ToString() != "index")
                type = Request.QueryString["type"].ToString() + "_detail";
            TMeta.Type = type;
            if (txtDetailTitle.Value.Trim().Equals(string.Empty))
                Restr += "详细页标题、";
            else
                TMeta.Title = txtDetailTitle.Value.Trim();
            if (txtDetailDescription.Value.Trim().Equals(string.Empty))
                Restr += "详细页描述、";
            else
                TMeta.Descriptions = txtDetailDescription.Value.Trim();
            if (txtDetailKeywords.Value.Trim().Equals(string.Empty))
                Restr += "详细页关键字、";
            else
                TMeta.Keywords = txtDetailKeywords.Value.Trim();
            if (Restr != "")
            {
                Restr = Restr.TrimEnd('、');
                lblMessage.Visible = true;
                lblMessage.Text = Restr + "填写有误！";
                return;
            }
            else
            {
                RMeta.Update(TMeta);
                ShowMessage("保存成功！");
            }
        }
    }
}
